﻿Public Class registroalmuerzosEMP

    Public Sub Mostrar()
        If guardar.Enabled = False Then
            guardar.Enabled = True
            cancelar.Enabled = True
            agregar.Enabled = False
            modificar.Enabled = False
            eliminar.Enabled = False
            imprimir.Enabled = False
            PanelArriba.Enabled = True
            PanelAbajo.Enabled = False
        Else
            cancelar.Enabled = False
            guardar.Enabled = False
            agregar.Enabled = True
            modificar.Enabled = True
            eliminar.Enabled = True
            imprimir.Enabled = True
            PanelArriba.Enabled = False
            PanelAbajo.Enabled = True

        End If
    End Sub

    Private Sub RegistroalmuerzosBindingNavigatorSaveItem_Click(sender As System.Object, e As System.EventArgs)
        Me.Validate()
        Me.RegistroalmuerzosBindingSource.EndEdit()
        Me.TableAdapterManager.UpdateAll(Me.DbFireAndIceDataSet)

    End Sub

    Private Sub registroalmuerzosEMP_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.itemventa' table. You can move, or remove it, as needed.
        Me.ItemventaTableAdapter.Fill(Me.DbFireAndIceDataSet.itemventa)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.empleados' table. You can move, or remove it, as needed.
        Me.EmpleadosTableAdapter.Fill(Me.DbFireAndIceDataSet.empleados)
        'TODO: This line of code loads data into the 'DbFireAndIceDataSet.registroalmuerzos' table. You can move, or remove it, as needed.
        Me.RegistroalmuerzosTableAdapter.Fill(Me.DbFireAndIceDataSet.registroalmuerzos)

    End Sub

    Private Sub agregar_Click(sender As System.Object, e As System.EventArgs) Handles agregar.Click
        BindingNavigatorAddNewItem.PerformClick()
        Mostrar()
    End Sub

    Private Sub modificar_Click(sender As System.Object, e As System.EventArgs) Handles modificar.Click
        Mostrar()
    End Sub

    Private Sub eliminar_Click(sender As System.Object, e As System.EventArgs) Handles eliminar.Click
        Dim opcion As Integer
        opcion = MsgBox("¿Está seguro que desea eliminar el registro?", MsgBoxStyle.YesNo + MsgBoxStyle.Question, "Eliminar registro")
        If opcion = vbYes Then
            Try
                'TipospagoTableAdapter.DeleteQuery(IdtipopagoTextBox.Text)
                Me.RegistroalmuerzosTableAdapter.Fill(Me.DbFireAndIceDataSet.registroalmuerzos)
            Catch ex As Exception
                MsgBox("Lo sentimos, el registro no puede ser eliminado ya que está relacionado con otras tablas", MsgBoxStyle.Critical, "Error")
            End Try
        End If
    End Sub

    Private Sub guardar_Click(sender As System.Object, e As System.EventArgs) Handles guardar.Click
        If IdempleadoTextEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(IdempleadoTextEdit, "Debe ingresar un nombre para el Empleado")
        ElseIf FechaDateTimePicker.Text.Length = 0 Then
            ErrorProvider1.SetError(FechaDateTimePicker, "Debe ingresar una fecha")
        ElseIf HoraTextBox.Text.Length = 0 Then
            ErrorProvider1.SetError(HoraTextBox, "Debe ingresar una hora")
        ElseIf IditemventaTextEdit.Text.Length = 0 Then
            ErrorProvider1.SetError(IditemventaTextEdit, "Debe ingresar una almuerzo")
        Else
            ErrorProvider1.SetError(IdempleadoTextEdit, Nothing)
            ErrorProvider1.SetError(FechaDateTimePicker, Nothing)
            ErrorProvider1.SetError(HoraTextBox, Nothing)
            ErrorProvider1.SetError(IditemventaTextEdit, Nothing)

            'DeduccionescategoriaBindingNavigatorSaveItem.PerformClick()
            MessageBox.Show("Se guardó el resgistro satisfactoriamente")
            Mostrar()
        End If
    End Sub

    Private Sub cancelar_Click(sender As System.Object, e As System.EventArgs) Handles cancelar.Click
        ErrorProvider1.SetError(IdempleadoTextEdit, Nothing)
        ErrorProvider1.SetError(FechaDateTimePicker, Nothing)
        ErrorProvider1.SetError(HoraTextBox, Nothing)
        ErrorProvider1.SetError(IditemventaTextEdit, Nothing)

        Mostrar()
        Me.RegistroalmuerzosTableAdapter.Fill(Me.DbFireAndIceDataSet.registroalmuerzos)
    End Sub

    Private Sub imprimir_Click(sender As System.Object, e As System.EventArgs) Handles imprimir.Click
        GridControl1.ShowPrintPreview()
    End Sub

    Private Sub IditemventaTextEdit_EditValueChanged(sender As System.Object, e As System.EventArgs) Handles IditemventaTextEdit.EditValueChanged
        If IsArray(Not IsDBNull(IditemventaTextEdit.EditValue)) Then
            TotalTextBox.Text = IditemventaTextEdit.GetColumnValue("precioventa")
        End If
    End Sub
End Class